﻿using SYMetro.Domain.Modal.Membership;
using SYMetro.Domain.Repository.Membership;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YiDa.Domain.Repositories;
using YiDa.Domain.Specifications;
using YiDa.Repository.EntityFramework;

namespace SYMetro.Repository.EntityFramework.Membership
{
    public class RoleRepository : EntityFrameworkRepository<Role>, IRoleRepository
    {
        public RoleRepository(IRepositoryContext context)
            : base(context)
        {

        }

        public IEnumerable<string> GetAncestorRoleNames(Guid RoleId)
        {
            var context = this.EFContext.Context as SYMetroDbContext;
            return context.Database.SqlQuery<string>("select RoleName from dbo.Roles_Ancestor_TVF(@p0)", RoleId);
        }


        public IEnumerable<Role> GetRolesByUserIn(string userName)
        {
            var context = this.EFContext.Context as SYMetroDbContext;
            var result = from r in context.Roles
                         from u in r.Users
                         where u.UserName == userName
                         select r;
            return result.ToList();
        }
    }
}
